package com.gf.framework.rabbitmq.core;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author gaofei
 * @date 2022/6/12 14:11
 */
public abstract class GfRabbitTemplete implements MessagePostProcessor {
    @Autowired
    protected RabbitTemplate rabbitTemplate;

    public void convertAndSend(String exchange, String routingKey, Object message) {
        rabbitTemplate.convertAndSend(exchange, routingKey, message, this);
    }

    @Override
    public Message postProcessMessage(Message message) {
        setMessageProperties(message.getMessageProperties());
        return message;
    }

    public abstract void setMessageProperties(MessageProperties properties);
}
